#!/usr/bin/env python
#-*- coding:utf-8 -*-

import os.path, logging
from core.core import Parser
from core.interpreter import SimpleInterpreter

VERSION = '20100408'
LOG_FILENAME = 'shorp.log'
logger = logging.getLogger('shorp')

class Shorp:
    
    def __init__(self):
        self.content = ''
        self.parser = None
        self.interpreter = None
            
    def addAll(self, all):
        for i in all:
            self.add(i)
        return self
            
    def add(self, source):
        if os.path.isfile(source):
            fh = open(source, 'r')
            self.content = self.content + fh.read()
        else:
            self.content = self.content + source
    
    def parse(self):
        if self.parser is None : self.parser = Parser()
        return self.parser.parse(self.content)
    
    def run(self):
        if self.interpreter is None: self.interpreter = SimpleInterpreter()
        root = self.parse()
        return self.interpreter.interpret(root)
        